<?php $thisLocation = 'root'; ?>
<?php
//TG 19/7/09
require_once('./config.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Search results</title>
<?php require_once('cms/admin/theme/maintheme.php');?>
</head>
<body>

<div id="wrap">
	<div id="header">
   <?php  require_once('cms/includes/header.php'); echo "\n"; ?>
  </div>
	<div id="content">
<?php

  include ('cms/functions/le-format.php');
  include ('cms/functions/convert-characters.php');

?>

<h1>Search Results</h1>

<?php

  // Convert case and trim ends
  $theSearch = trim(strtolower($_POST['search_term']));
  // Strip out extra spaces in search string
  $theSearch = preg_replace("/[ ]+/", " ", $theSearch);
  // Check for a result
  $number = str_word_count($theSearch);
  if ($number < 1) {
    $problem = true;
    echo "<p>You didn't enter a search term.</p>\n";
  } else {
    echo "<h2>Pages found for <span>$theSearch<span></h2>\n\n";
  }

  // If something was searched for...
  if (!$problem) {
     //TG
     //echo "there is no problem<br>";
     //TG
    $filename = "./cms/search/index.txt";
    //TG
    //echo "filename is $filename<br>";
    
    $fp = fopen($filename, "r") or die("Couldn't open $filename.");
    // Loop through all the lines
    while (!feof($fp)) {
      $line = fgets($fp, 1024);
      $line = strtolower($line);
      // Check each line for search term
      if (preg_match("/\b$theSearch\b/", $line)) { // \b = boundary
        $result = true;
        // Convert line string into array
        $lineArray = explode("|", $line);
        //TG
        //print_r($lineArray);
        // Print first element
        //TG
        $lineArray[0] = $wwwroot."/cms".$lineArray[0].".php";
        //TG
        //print_r($lineArray);
        
        echo '<h5><a href="' . $lineArray[0] . '" title="' . $lineArray[1] . '">' . $lineArray[1] . '</a></h5>';
        echo "\n";
        // Slice off after 2nd element to new array
        $keywords = array_slice($lineArray, 2);
        // Loop through each array for the keywords
        echo "<p><small><span>Keywords:</span> ";
        foreach ($keywords as $val) {
          echo "<span>|</span> $val ";
        }
        echo " <span>|</span></small></p>\n";
      } // End of match conditional
    } // End of while loop
    if (!$result) {
      echo '<p>Sorry, no match was found for <span>' . $theSearch . '</span>.</p>';
      echo "\n";
    }
  }

?>

	</div><!-- content_eof //-->
	<div id="navigation">

<ul id="menu">
<li><a href="<?php echo $wwwroot ?>" title="Home Page">Home Page</a></li>
<?php

  include ('cms/classes/makebutton.class.php');
  include ('cms/includes/menu.php');

?>
<li><a href="<?php echo $wwwroot ?>/contact.php" title="Contact">Contact</a></li>

</ul>

	</div><!-- navigation_eof //-->
	<div id="extra">

<?php include ('cms/includes/extra.php'); echo "\n"; ?>

	</div><!-- extra_eof //-->
	<div id="search">

<?php include ('cms/includes/searchform.php'); ?>

	</div><!-- search_eof //-->
	<div id="footer">

<p><?php include ('cms/includes/footer.inc'); ?></p>

<?php include ('cms/includes/tracking.php'); ?>

	</div><!-- footer_eof //-->
</div><!-- wrap_eof //-->

</body>
</html>
